
// 注册表单公司名称
var ted = document.getElementById('inp12');
var tedp = document.getElementById('p12');
ted.onfocus = function(){
    tedp.innerHTML = ""
}

function mingfn(){
    if(ted.value == ""){
        tedp.innerHTML = "*公司名称不可以为空";
        return false;
    }else {
      tedp.innerHTML = '<img src="/pc/login/img/success.png" style="height:16px ;width:16px" />'
    }
}
ted.onblur = mingfn;
// 注册表单联系人
var con = document.getElementById('inp13');
var conp = document.getElementById('p13');
con.onfocus = function(){
    conp.innerHTML = ""
}

function renfn(){
    if(con .value == ""){
        conp.innerHTML = "*联系人不可以为空";
        return false;
    }else {
      conp.innerHTML = '<img src="/pc/login/img/success.png" style="height:16px ;width:16px" />'
    }
}
con.onblur = renfn;
   //注册表单的 账号
 var oUser = document.getElementById('inp1');
var oUserInfo = document.getElementById('p1');
oUser.onfocus = function(){
    oUserInfo.innerHTML = "*请输入字母/数字/下划线构成，首字母不是数字，4-24位的账号"
}
function userfn(){
    if(oUser.value == ""){
        oUserInfo.innerHTML = "*账号不可以为空";
        return false;
    }
     var regex = /^[a-zA-Z_]\w{3,23}$/;
    if(regex.test(oUser.value) == true){
        // console.log(111)
        $.ajax({
          url: '/admin/login/account',
          type: 'POST',
           async:false,
             data:{
               '_token':$('input[name=_token]').val(),
              'user':oUser.value,
          },
          success: function (data) {
            if (data == "0") {
                   oUserInfo.innerHTML = "*该账号已被注册!!";
                  return false;
               }
               else if (data == "1") {
                 oUserInfo.innerHTML = '<img src="/pc/login/img/success.png" style="height:16px ;width:16px" />';
                  return true;
                }
            }
        });

}else{
        oUserInfo.innerHTML = "*账号格式不对";
        return false;
    }
        
}
oUser.onblur = userfn;
  //注册表单的 手机号
var oTel = document.getElementById('inp2');
var oTelInfo = document.getElementById('p2');
oTel.onfocus = function () {
    oTelInfo.innerHTML = "";
}

function telfn() {
    if(oTel.value == "") {
        oTelInfo.innerHTML = "*手机号不能为空";
        return false;
    }

    var regex = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
    if(regex.test(oTel.value) == true) {        
              $.ajax({
                        url:"/admin/login/phone",
                        type:"post",
                        data: {'_token':$('input[name=_token]').val(), 'mobile':oTel.value},
                        dataType: "html",
                        success: function (aaa)
                        {
                            if (aaa == 1) {
                              oTelInfo.innerHTML ='<img src="/pc/login/img/success.png" style="height:16px ;width:16px" />';
                              return true;
                            } else {
                                $('#p2').html("*该手机号已被注册!!");
                                return false;
                            }
                        }
                    });        
    } else {
        oTelInfo.innerHTML = "*手机格式输入不正确";
        return false;
    }
}
oTel.onblur = telfn;

// 注册表单的密码
var oPsd = document.getElementById('inp3');
var oPsdInfo = document.getElementById('p3');
oPsd.onfocus = function () {
    oPsdInfo.innerHTML = "*由6-24位数字,字母或符号组成";
}

function psdfn() {
    if(oPsd.value == ""){
        oPsdInfo.innerHTML ="*密码不能为空";

        return false;
    }
    // var regex = /(?!^[0-9]+$)(?!^[A-z]+$)(?!^[^A-z0-9]+$)^.{6,24}$/;
    // 6~24位纯数字或纯字母或者纯字符或者字母数字字符至少两种以上的正则表达式
       var regex = /^[\x21-\x7E]{6,24}$/;
    if(regex.test(oPsd.value) == true){
        oPsdInfo.innerHTML ='<img src="/pc/login/img/success.png" style="height:16px ;width:16px" />';


        return true;
    } else {
        oPsdInfo.innerHTML = "*密码格式不对";

        return false;
    }
}
oPsd.onblur = psdfn; 

// 注册表单的密码确认
var oRpsd = document.getElementById('inp4');
var oRpsdInfo = document.getElementById('p4');
oRpsd.onfocus = function(){
    oRpsdInfo.innerHTML = "";
}

function rpsdfn() {
    if(oRpsd.value == "") {
        oRpsdInfo.innerHTML = "*确认密码不能为空";

        return false;
    }
    if(oRpsd.value == oPsd.value) {
        oRpsdInfo.innerHTML = '<img src="/pc/login/img/success.png" style="height:16px ;width:16px" />';
        return true;
    } else {
        oRpsdInfo.innerHTML = "*密码输入不一致";
        return false;
    }
}
oRpsd.onblur = rpsdfn;
$("#xl option:first").prop("selected", 'selected');
// 注册表单的下拉选框
var xl = document.getElementById('xl');
var xlInfo = document.getElementById('p5');
xl.onfocus = function(){
    xlInfo.innerHTML = "";
}
function xlfn() {
  if(xl.value == "") {
      xlInfo.innerHTML = "*代理商不能为空";
      return false;
  }else{
    xlInfo.innerHTML ='<img src="/pc/login/img/success.png" style="height:16px ;width:16px" />';
      return true;
  }
}
xl.onblur = xlfn;

// 登陆表单账号/手机验证
var oTel1 = document.getElementById('inp5');
var oTelInfo1 = document.getElementById('p6');
oTel1.onfocus = function () {
    oTelInfo1.innerHTML = "";
}
function telfn1() {
    if( oTel1.value == "") {
        oTelInfo1.innerHTML = "*账号/手机号不能为空";
        return false;
    }
    var regex1 = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
      var zhanghao =  /^[a-zA-Z_]\w{3,23}$/;
    if( zhanghao.test(oTel1.value)  || regex1.test(oTel1.value) == true) {
        oTelInfo1.innerHTML = '<img src="/pc/login/img/success.png" style="height:16px ;width:16px" />';
        return true;
    }  else {
        oTelInfo1.innerHTML = "*账号/手机格式输入不正确";
        return false;
    }
}
oTel1.onblur = telfn1;
// 登陆表单密码验证
var oPsd2 = document.getElementById('inp6');
var oPsdInfo2 = document.getElementById('p7');
oPsd2.onfocus = function () {
    oPsdInfo2.innerHTML = "";
}
function psdfn1() {
    if(oPsd2.value == ""){
        oPsdInfo2.innerHTML ="*密码不能为空";
        return false;
    }
    var regex2 = /^[\x21-\x7E]{6,24}$/;
    if(regex2.test(oPsd2.value) == true){
        oPsdInfo2.innerHTML ='<img src="/pc/login/img/success.png" style="height:16px ;width:16px" />';
        return true;
    } else {
        oPsdInfo2.innerHTML = "*密码格式不对";
        return false;
    }
}
oPsd2.onblur = psdfn1; 

//回车键登录
$(document).keyup(function(event){
  if(event.keyCode ==13){
    //规定被选元素要触发的事件
    $("#btn2").trigger("click");
  }
});

// 忘记密码表单手机验证
var oTel3 = document.getElementById('inp7');
var oTelInfo3 = document.getElementById('p8');
oTel3.onfocus = function () {
    oTelInfo3.innerHTML = "";
}

function telfn2() {
    if(oTel3.value == "") {
        oTelInfo3.innerHTML = "*手机号不能为空";
        return false;
    }

    // var regex3 = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
    // if(regex3.test(oTel3.value) == true) {
    //     oTelInfo3.innerHTML = '<img src="/pc/login/img/success.png" style="height:16px ;width:16px" />';
    //     return true;
    // } else {
    //     oTelInfo3.innerHTML = "*手机格式输入不正确";
    //     return false;
    // }
    var regex3 = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
     if(regex3.test(oTel3.value) == true) {        
              $.ajax({
                        url:"/admin/login/userphone",
                        type:"post",
                        data: {
                            '_token':$('input[name=_token]').val(), 
                            'mobile':oTel3.value
                        },
                        dataType: "html",
                        success: function (aaa)
                        {
                            if (aaa == 0) {
                              oTelInfo3.innerHTML ='<img src="/pc/login/img/success.png" style="height:16px ;width:16px" />';
                              return true;
                            } else if (aaa == 1){
                              oTelInfo3.innerHTML = "*手机号尚未注册成功"
                                return false;
                            }
                        }
                    });        
    } else {
        oTelInfo.innerHTML = "*手机格式输入不正确";
        return false;
    }
}
oTel3.onblur = telfn2;
 
//忘记密码表单验证码验证
var pin = document.getElementById('inp10');
var pinInfo = document.getElementById('p11');
pin.onfocus = function () {
    pinInfo.innerHTML = "";
}
function pinfn2() {
    if((pin.value == "") || (pin.value !=msgcode)) {
        pinInfo.innerHTML = "*验证码不正确";
        return false;
    }

    var yanzheng = /^\d{4}$/;
    if(yanzheng.test(pin.value) == true) {
        pinInfo.innerHTML = '<img src="/pc/login/img/success.png" style="height:16px;width:16px" />';
        return true;
    } else {
        pinInfo.innerHTML = "*验证码输入不正确";
        return false;
    }
}
pin.onblur = pinfn2;
// 忘记密码表单60倒计时
var k = 60;
var time = null;
document.getElementById("pn11").onclick=function(){
    var sg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
    var phone = $('#inp7').val();
    if(($('#inp7').val() == "") || (sg.test($('#inp7').val()) == false))
    {

    } else {
        $("#pn11").css("background","rgba(255,255,255,0.8)");
        $('#p11').html("验证码已发送至您的手机");
        if (time == null) {
            time = setInterval( function ()
            {
                k--;
                if (k == 59) {
                    $.ajax({
                        url:"/admin/login/code",
                        type:"post",
                        data: {'_token':$('input[name=_token]').val(), 'mobile':phone},
                        dataType: "html",
                        success: function (num)
                        {
                            if (num) {
                                // console.log(num);
                                msgcode = num;
                            } else {
                                $('#p11').html("短信验证码发送失败");
                            }
                        }
                    });
                }
                $('#pn11').val(k+' s');
                if (k<=0) {
                    clearInterval(time);
                    k = 60;
                    msgcode = '';
                    time = null;
                    $('#msg').val('');
                    $('#pn11').val('获取验证码');
                    $('#p11').html('');
                }
            },1020);
        }
    }
} 
// 注册表单判断跳转条件
function fn() {
    var p1 = false;
    var p2 = false;
    if($("#p1").html() == '<img src="/pc/login/img/success.png" style="height:16px ;width:16px">'){
        p1 = true;
    };
    if($("#p2").html() == '<img src="/pc/login/img/success.png" style="height:16px ;width:16px">'){
        p2 = true;
    }
   if( $("#slider1 > .ui-slider-wrap > .ui-slider-no-select").text()=="验证成功" ){
        // var res1 = userfn();    
        // var res2 = telfn();
        var res3 = psdfn();
        var res4= rpsdfn();
        var res5 = xlfn();
        var res12 = mingfn();
        var res13 = renfn();
    return p1 && p2  && res3 && res4 && res5 && res12 && res13;
    }else{    
        return false;
    }
}
// 登录表单判断跳转条件
function fn1() {
    
    if($("#slider2 > .ui-slider-wrap > .ui-slider-no-select").text()=="验证成功"){
       var res9 = telfn1();
       var res10 = psdfn1();
      return res9 && res10;
    }else{       
        return false;
    }
}
// 忘记密码判断跳转判断
function fn2() {
    var res6 = telfn2();
    var res11 = pinfn2();
    return res6 && res11;
}

